package com.rupertjones.globalcron.server.resources;

import org.brownflat.dbinit.upgrade.Upgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0007CreateAuth implements Upgrade {

    private static final int VERSION = 7;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
        return "CREATE TABLE `user` (\n"
                + "  `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + "  `username` varchar(100) NOT NULL,\n"
                + "  `password` varchar(100) DEFAULT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `id_UNIQUE` (`id`),\n"
                + "  UNIQUE KEY `name_UNIQUE` (`username`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `user_role` (\n"
                + "  `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + "  `user` int(11) NOT NULL,\n"
                + "  `role` int(11) DEFAULT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `id_UNIQUE` (`id`),\n"
                + "  UNIQUE INDEX `user_unique_role` (`user` ASC, `role` ASC)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `role` (\n"
                + "  `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + "  `name` varchar(100) NOT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `id_UNIQUE` (`id`),\n"
                + "  UNIQUE KEY `name_UNIQUE` (`name`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;\n";
    }

    @Override
    public String getName() {
        return "Create auth tables";
    }
}
